<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>简单工厂模式</title>
</head>
<body>
  <script>
    // 可以利用工厂函数批量创建结构相同内容相似的对象
    function factory (name, age) {
      var o = new Object()
      o.name = name
      o.age = age
      return o
    }

    // 通过直接调用工厂函数得到对象，而不用自己每次new了
    var obj1 = factory('zhangsan', 20)
    var obj2 = factory('lisi', 18)


  </script>
</body>
</html>